<template>
<div align="center">
  <el-button type="warning"  @click="changUserId"
             size="medium"
             style="margin-left: 800px;"
             plain>切换用户</el-button>当前用户：{{this.queryForm.userId}}
  <el-table
      :data="tableData"
      stripe
      align="center"
      style="width: 100%">
    <el-table-column
        prop="entrustTime"
        label="委托时间"
        width="180">
    </el-table-column>
    <el-table-column
        prop="entrustStockCode"
        label="股票代码"
        width="180">
    </el-table-column>
    <el-table-column
        prop="entrustBankName"
        width="180"
        label="股票名称">
    </el-table-column>
    <el-table-column
        prop="entrustPrice"
        label="委托价格"
        width="180">
    </el-table-column>
    <el-table-column
        prop="entrustNum"
        width="180"
        label="委托数量">
    </el-table-column>
    <el-table-column
        prop="entrustDirection"
        label="方向"
        width="180">
    </el-table-column>
    <el-table-column
        prop="entrustStatus"
        width="180"
        label="状态">
    </el-table-column>
    <el-table-column
        width="180"
        label="">
      <template v-slot="scope">
        <el-button type="primary" size="mini" @click="updateStatus(scope.row)">撤单</el-button>
      </template>
    </el-table-column>
  </el-table>
  <!--       分页-->
  <el-pagination
      background
      :page-size="this.queryForm.pageSize"
      :current-page="this.queryForm.pageSize"
      @current-change="toNewPage"
      layout="prev, pager, next"
      :total="total">
  </el-pagination>
</div>
</template>

<script>
export default {
  name: "TodayEntrustView",
  data(){
    return{
      tableData:[],
      queryForm:{
        pageNum:1,
        pageSize:3,
        userId:1,
      },
      total:0,
    }
  },
  created() {
    this.getEntrustList();
  },
  methods:{
    //切换用户
    changUserId(){
      if(this.queryForm.userId==1){
        this.queryForm.userId=4;
      }else if(this.queryForm.userId==4){
        this.queryForm.userId=1;
      }
      console.log(this.queryForm.userId);
      this.getEntrustList();
    },
    //分页
    toNewPage(newPage){
      this.queryForm.pageNum=newPage;
      this.getEntrustList();
    },
    //撤单
    updateStatus(row){
      row.entrustStatus="撤单";
      row.haveId=this.queryForm.userId;
      this.axios.post("http://localhost:8182/stock/updateEntrustByStatus",row).then(r=>{
        if(r.data.code==200){
          this.$message.success("撤单成功");
          window.setTimeout(function (){
            window.location.reload();
          },500)
        }else {
          this.$message.error(r.data.msg);
        }
      })
    },
    //获得用户对应的委托列表
    getEntrustList(){
      this.axios.post("http://localhost:8182/stock/getTodayEntrustList",this.queryForm).then(r=>{
        this.tableData=r.data.data.list;
        this.total=r.data.data.total;
      })
    },
  }
}
</script>

<style scoped>

</style>